//
// Created by yangchao on 2022/5/5.
// 38. 外观数列: https://leetcode-cn.com/problems/count-and-say/
//

#include <string>
#include <iostream>
using namespace std;

class CountAndSay{
public:
    string countAndSay(int n) {
        if (n == 1) return "1";
        string str = countAndSay(n-1);
        string res = "";
        int count = 1;
        char pre = str[0];
        for (int i = 1; i < str.size(); ++i) {
            if (str[i] == pre) {
                count++;
                continue;
            } else {
                res.push_back(count+'0');
                res.push_back(pre);
                pre = str[i];
                count = 1;
            }
        }
        res.push_back(count+'0');
        res.push_back(str[str.size()-1]);
        return res;
    }
};

int main() {
    CountAndSay Ca;
    string res = Ca.countAndSay(4);
    cout << res << endl;
    return 0;
}
